<?php
class Managecategory_Data_Addform {
	
	private $form;
	private $database;
	
	public function __construct(){
		$this->form = new Core_Driver_Firstform();
		$this->database = new Core_Driver_MysqlImproved();
	}
	
	public function getForm(){
		$privileges = $this->getAccessLevels();
		$categoryForm = $this->form->startForm(
			array(
			"action" => SERVER_ROOT."?managecategory&page=added",
					"method" => "post"
		)
		);
		$categoryForm .= $this->form->inputForm(
			array(
			"type" => "hidden",
					"name" => "addCategory",
					"value" => "addCategory"
		),
				null
		);
		$categoryForm .= ADD_CATEGORY_MESSAGE;
		$categoryForm .= "<ul>";
		$categoryForm .= "<li>";
		$categoryForm .= $this->form->labelForm(
				array(
						"for" => "name"
				),
				ADD_CATEGORY_NAME,
				null
		);
		$categoryForm .= $this->form->inputForm(
				array(
						"name" => "name",
						"placeholder" => ADD_CATEGORY_NAME_PLACEHOLDER,
						"type" => "text",
						"id" => "title",
						"maxlength" => "255"
				),
				"required autofocus"
		);
		$categoryForm .= "</li>";
		$categoryForm .= "<li>";
		$categoryForm .= $this->form->labelForm(
			array(
			"for" => "privileges"
		),
				ADD_CATEGORY_ACCESS_LEVEL
		);
		$categoryForm .= $this->form->selectForm(
			array(
			"name" => "privileges",
					"id" => "privileges"
		),
				"required",
				$privileges
		);
		$categoryForm .= "</li>";
		$categoryForm .= "<li>";
		$categoryForm .= $this->form->labelForm(
			array(
			"for" => "title"
		),
				ADD_CATEGORY_META_TITLE,
				null
		);
		$categoryForm .= $this->form->inputForm(
			array(
			"name" => "title",
					"placeholder" => ADD_CATEGORY_META_TITLE_PLACEHOLDER,
					"type" => "text",
					"id" => "title",
					"maxlength" => "255"
		),
				"required autofocus"
		);
		$categoryForm .= "</li>";
		$categoryForm .= "<li>";
		$categoryForm .= $this->form->labelForm(
			array(
			"for" => "keywords"
		),
				ADD_CATEGORY_KEYWORDS,
				null
		);
		$categoryForm .= $this->form->textareaForm(
			array(
			"name" => "keywords",
					"id" => "keywords",
					"placeholder" => ADD_CATEGORY_KEYWORDS_PLACEHOLDER,
					"maxlength" => "1000",
					"style" => "height: 30em"
		),
				"required",
				null
		);
		$categoryForm .= "</li>";
		$categoryForm .= "<li>";
		$categoryForm .= $this->form->labelForm(
			array(
			"for" => "description"
		),
				ADD_CATEGORY_META_DESCRIPTION,
				null
		);
		$categoryForm .= $this->form->textareaForm(
			array(
			"name" => "description",
					"id" => "description",
					"placeholder" => ADD_CATEGORY_META_DESCRIPTION_PLACEHOLDER,
					"maxlegth" => "1000",
					"style" => "height: 30em;"
		),
				"required",
				null
		);
		$categoryForm .= "</li>";
		$categoryForm .= "</ul>";
		$categoryForm .= '<div class = "buttons">';
		$categoryForm .= $this->form->inputForm(
			array(
			"type" => "submit",
					"name" => "submit",
					"value" => ADD_CATEGORY_BUTTON
		),
				null
		);
		$categoryForm .= "</div>";
		$categoryForm .= $this->form->endForm();
		return $categoryForm;
	}
	
	private function getAccessLevels(){
		$this->database->connect();
		$this->database->prepare(
			"
				SELECT * FROM privileges ORDER BY privileges_types ASC;
				"
		);
		$this->database->query();
		$privilegesData = array();
		while($privileges = $this->database->fetch('array')){
			$privilegesData[$privileges['privileges_types']] = "(".$privileges['privileges_types'].") ".$privileges['privileges_name'];
		}
		return $privilegesData;
	}
	
}